package com.yyfax.pay.depository.controller.web;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.alibaba.fastjson.JSON;
import com.yyfax.pay.common.model.vo.RedirectFormVO;
import com.yyfax.pay.depository.domain.FuiouCharge;
import com.yyfax.pay.depository.service.inner.ChargeInnerService;
import com.yyfax.pay.third.model.to.fuioudeposit.EBankChargeBackReq;

/**
 * 充值网关同步结果通知入口
 * 
 * @author buyi
 * @date 2017-09-02 10:10:17
 * @since v2.0.0
 */
@Controller
public class ChargeResultWebController {

	@Resource
	private ChargeInnerService chargeInnerService;

	/**
	 * 网银同步返回请求入口
	 * 
	 * @author buyi
	 * @date 2017-09-02 10:38:15
	 * @since v2.0.0
	 * @param merchantCode
	 * @param req
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(method = RequestMethod.POST, path = "/web/fuiou/charge/ebank/result/back/{merchantCode}")
	public String ebankBack(@PathVariable("merchantCode") String merchantCode, EBankChargeBackReq req, Model model) throws Exception {
		 FuiouCharge po = chargeInnerService.parseEbankBackResult(merchantCode, req);

		// 解析网银同步返回结果
		RedirectFormVO<?> routeFormVO = chargeInnerService.getRouteForm(po);
		model.addAttribute("url", routeFormVO.getUrl());
		model.addAttribute("form", JSON.toJSON(routeFormVO.getParams()));

		return "fuioudeposit/guide";
	}
}
